package com.acwing.partition11;

import java.io.*;

public class AC1019庆功会 {

    private static final int N = 510, M = 6010;
    private static int[] vs = new int[N], ws = new int[N], cnts = new int[N], f = new int[M];
    private static int n, m;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt(); m = nextInt();
        for (int i = 1; i <= n; i++) {
            vs[i] = nextInt();
            ws[i] = nextInt();
            cnts[i] = nextInt();
        }
        for (int i = 1; i <= n; i++) {
            int v = vs[i], w = ws[i], cnt = cnts[i];
            for (int k = 1; k <= cnt; k <<= 1) {
                for (int j = m; j >= k * v; j--) {
                    f[j] = Math.max(f[j], f[j - k * v] + w * k);
                }
                cnt -= k;
            }
            for (int j = m; cnt != 0 && j >= cnt * v; j--) {
                f[j] = Math.max(f[j], f[j - cnt * v] + cnt * w);
            }
        }
        writer.println(f[m]);
        writer.flush();
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
